package com.ggh.controller;
import	java.util.Date;

import com.ggh.entity.Ai;
import com.ggh.service.AiService;
import com.ggh.vo.Body;
import com.ggh.vo.Meta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author jj
 * @date 2019/10/22 10:00
 * 机器人
 */
@Controller
@RequestMapping("/ai")
public class AiController {
    /**
     * 用户查询
     */
  @Autowired
  private AiService aiService;
  /**
  * @description :添加机器人到数据库
  * @param ai
  * @date : 2019/10/22 12:17
  * @author : jj
  */
  @PostMapping("/add")
  @ResponseBody
  @Transactional(rollbackFor = Exception.class)
  public Body add(Ai ai) {
      ai.setCreatetime(new Date());
      boolean b = ai.insert();
      return b ? Body.newInstance() : Body.newInstance(Meta.CODE_451);
  }
  @PostMapping("/addgame")
  @ResponseBody
  public Body addGame(Ai ai){
      Body body = aiService.addGame(ai);
      return body;
  }
    @PostMapping("/exitgame")
    @ResponseBody
    public Body exitGame(Ai ai){
        Body body = aiService.exitGame(ai);
        return body;
    }

}
